﻿using System.Collections.Generic;
using System.Linq;
using Devbridge.IPolice.DataContracts;
using Devbridge.IPolice.DomainModel;

namespace Devbridge.IPolice.RepositoriesMock
{
    public class CrimeRepositoryMock : ICrimeRepository
    {
        private readonly IList<Crime> crimes;

        public CrimeRepositoryMock()
        {
            crimes = new List<Crime>();

            crimes.Add(new Crime { });
            crimes.Add(new Crime { });
            crimes.Add(new Crime { });
        }

        public Crime GetById(int id)
        {
            Crime crime = AllQuery().FirstOrDefault(p => p.Id == id);

            return crime;
        }

        public IQueryable<Crime> AllQuery()
        {
            return crimes.AsQueryable();
        }

        public void Remove(Crime entity)
        {
            crimes.Remove(entity);
        }

        public void Save(Crime entity)
        {
            crimes.Add(entity);
        }

        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        /// <filterpriority>2</filterpriority>
        public void Dispose()
        {
            crimes.Clear();
        }
    }
}